package com.itxckf.mapper;

import com.itxckf.pojo.DeleteOrderProductsFrom;
import com.itxckf.pojo.Order;
import com.itxckf.pojo.OrderProducts;
import com.itxckf.pojo.Products;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {


    List<Order> getOrder(@Param("name") String name,@Param("sts") String sts);

    void updateOrder(Order order);

    @Select("SELECT o.*,p.*,op.* FROM Orders o JOIN OrderProducts op ON o.OrderID = op.OrderID JOIN Products p ON op.ProductID = p.ProductID WHERE o.OrderID = #{orderID};")
    List<Products> getOrderProducts(int orderID);

    void addOrderProducts(OrderProducts orderProducts);

    @Delete("DELETE op FROM OrderProducts op JOIN Orders o ON o.OrderID = op.OrderID WHERE o.OrderID = #{orderID} AND op.ProductID = #{ProductID};")
    void deleteOrderProducts(DeleteOrderProductsFrom orderProducts);

    void addOrder(Order order);

    int getLastInsertedOrderId();


    @Select("select * from Orders where OrderID = #{id}")
    Order queryOrder(Short id);
}
